package com.sq.auth.common.entity;

import com.sq.auth.common.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @author quan
 */
@Data
public class Result<T> {
    private Boolean success;
    private int code;
    private String message;
    private T data;

    public static Result ok(){
        Result result = new Result<>();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        result.setData(Boolean.TRUE);
        return result;
    }

    public static <T> Result ok(T data){
        Result result = new Result<>();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    public static Result fail(){
        Result result = new Result<>();
        result.setSuccess(Boolean.FALSE);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getMessage());
        return result;
    }

    public static <T> Result fail(T data){
        Result result = new Result<>();
        result.setSuccess(Boolean.FALSE);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getMessage());
        result.setData(data);
        return result;
    }
}
